package com.txtTool.articleTxt.utils;

import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class DocUtil {

    public static String doc_String(FileInputStream fs) throws IOException {
        StringBuilder result = new StringBuilder();
        XWPFDocument doc = new XWPFDocument(fs);
        XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
//        WordExtractor re = new WordExtractor(fs);
        result.append(extractor.getText());
        extractor.close();
        return result.toString();
    }

    public static String doc2String(File file) throws IOException {
        return doc_String(new FileInputStream(file));
    }

}
